<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="box"></div>
    <script>

        function jsonp(url) {
            let script = document.createElement('script');
            script.src = url;
            document.body.appendChild(script);
        }

        // 函数必须定义到外面
        function fn(data) {
            document.getElementById('box').innerHTML = `姓名：${data.name}，年龄：${data.age} `;
        }

        window.onload = function () {
            console.log(jsonp('http://localhost/jsonpServer'));
        }

    </script>

</body>

</html>